'''
Author: duliang thinktanker@163.com
Date: 2024-07-01 19:58:52
LastEditors: duliang thinktanker@163.com
LastEditTime: 2024-07-06 19:00:00
FilePath: \my---qq\temp.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
import uuid
import requests
import time
from datetime import datetime

SWURL = 'https://16gs832674.oicp.vip/qq'


# 2024年7月2号日14时，皂河二站未运行，上游水位21.54m，下游水位18.50m，邳洪河北闸六孔全开，开高5.0m，工况正常。
def get_uuid():
    return str(uuid.getnode())


def get_water_info():
    now_time = time.time()
    my_uuid = get_uuid()
    print(my_uuid)
    resp = requests.get(url=SWURL + '?i=' + my_uuid, timeout=10)
    if resp.status_code != 200:
        return None
    resp = resp.json()
    resp = resp['respdata']
    timestamp1 = resp[0][-1]
    delta_time1 = now_time - timestamp1
    resp[0][-1] = time.strftime('%Y-%m-%d %H:%M:%S',
                                time.localtime(timestamp1))
    date_format = "%Y-%m-%d %H:%M:%S"
    # 将字符串转换为 datetime 对象
    dt_object = datetime.strptime(resp[1][-1], date_format)
    # 将 datetime 对象转换为时间戳
    timestamp2 = time.mktime(dt_object.timetuple())
    delta_time2 = now_time - timestamp2
    # print(timestamp)
    if delta_time1 < delta_time2:
        return resp[0]
    else:
        return resp[1]


def getsw():
    sw = get_water_info()
    if sw:
        return f"{time.strftime('%Y年%m月%d日%H时', time.localtime(time.time()))}，刘老涧二站未运行，上游水位{sw[0]}m，下游水位{sw[1]}m，工况正常。"
    else:
        return "获取数据失败"


if __name__ == '__main__':
    print(getsw())
